﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="System.Web.UI.Page" %>

<%@ Import Namespace="Portal.Core.Helper" %>
<%@ Import Namespace="Portal.Data.Entity" %>

<script runat="server">
    private const string StrReplace = "(“|”)";
    private const string StrReplacer = "'";
    protected void Page_Load(object sender, EventArgs e)
    {
        var act = Request["act"] ?? "";
        var max = 0;
        int.TryParse(Request["max"], out max);
        if (max <= 0 || max > 16) max = 16;
        
        var list = new List<JsonBook>();
        switch (act)
        {
            case "latest":
                var temp = Book.FindLatestUpdate(0).Take(max);
                list.AddRange(from Book b in temp
                              select new JsonBook
                              {
                                  Id = b.ID,
                                  FullName = ReplaceSpecial(b.FullName),
                                  LastChapTitle = ReplaceSpecial(b.LastChapTitle),
                                  Url = b.Url,
                                  Image = Book.RenderImage(b.Image, 142),
                                  Author = b.CrawlAuthor,
                                  TotalChap = b.LastChapter,
                                  TotalVisit = b.Visited,
                                  Finish = b.Finish,
                                  ModifiedDate = b.ModifiedDate,
                                  Description = b.DescriptionSort()
                              });
                break;
        }
        if (list.Count > 0)
        {
            Response.Write(JsonHelper.JsonSerializer(list));
        }
        Response.End();
    }
    string ReplaceSpecial(string input)
    {
        var parser = new Portal.Core.Utils.HtmlParser();
        return parser.Replace(input, StrReplace, StrReplacer);
    }
    public class JsonBook
    {
        public int Id { get; set; }
        public string FullName { get; set; }
        public string Description { get; set; }
        public string LastChapTitle { get; set; }
        public string Url { get; set; }
        public string Image { get; set; }
        public string Author { get; set; }
        public int TotalChap { get; set; }
        public int TotalVisit { get; set; }
        public bool Finish { get; set; }
        public DateTime ModifiedDate { get; set; }
    }

</script>
<%-- ReSharper restore UnassignedField.Local --%>
